using System;
using System.Collections.Generic;
using System.Text;

namespace tKitchen
{
    public class UnitInputPresenter
    {
        tKitchenMain domain;
        UnitInput inputForm;


        public UnitInputPresenter(tKitchenMain domainIn)
        {
            domain = domainIn;
            inputForm = new UnitInput(this);
            
            PopulateGrid();
            inputForm.Show();


        }



        //Depricated?
        private string[,] ParseData(List<Unit> unitList)
        {
            int unitCount = unitList.Count;
            int name = 0;
            int abbrv = 1;
            int descr = 2;

            string[,] data = new string[3, unitCount];
            for (int i = 0; i < unitCount; i++)
            {
                data[name, i] = unitList[i].Name;
                data[abbrv, i] = unitList[i].Abbrev;
                data[descr, i] = unitList[i].Descr;
            }

            return data;
        }


        internal void AddUnit(string nameIn, string abbrevIn, string descrIn)
        {
            Unit tempUnit = new Unit();
            tempUnit.Name = nameIn;
            tempUnit.Abbrev = abbrevIn;
            tempUnit.Descr = descrIn;

            domain.AddUnit(tempUnit);

            PopulateGrid();

        }

        internal void UpdateUnit(Unit tempUnit)
        {
            domain.UpdateUnit(tempUnit);
            PopulateGrid();
        }


        private void PopulateGrid()
        {
            List<Unit> unitList = domain.GetUnitList();
            inputForm.SetDataSource(unitList);
            inputForm.RefreshGrid();
        }
    }
}
